package com.example.yigoumall.mapper;

import com.example.yigoumall.entity.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface UserMapper {
    
    @Select("SELECT * FROM easybuy_user")
    List<User> findAll();
    
    @Select("SELECT * FROM easybuy_user WHERE id = #{id}")
    User findById(Integer id);
    
    @Insert("INSERT INTO easybuy_user(loginName, userName, password, sex, identityCode, email, mobile, type, createTime) " +
            "VALUES(#{loginName}, #{userName}, #{password}, #{sex}, #{identityCode}, #{email}, #{mobile}, #{type}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User user);
    
    @Update("UPDATE easybuy_user SET loginName=#{loginName}, userName=#{userName}, password=#{password}, sex=#{sex}, " +
            "identityCode=#{identityCode}, email=#{email}, mobile=#{mobile}, type=#{type} WHERE id=#{id}")
    int update(User user);
    
    @Delete("DELETE FROM easybuy_user WHERE id=#{id}")
    int deleteById(Integer id);
    
    @Select("SELECT * FROM easybuy_user WHERE loginName = #{loginName}")
    User findByLoginName(String loginName);
}